package com.ptszyxx.popose.common.utils;


import android.content.Context;

import com.alibaba.fastjson.JSON;
import com.ysg.constant.FileConstant;
import com.ysg.http.data.entity.config.AppConfig;
import com.ysg.utils.YChannelUtil;
import com.ysg.utils.YDbUtils;
import com.ysg.utils.YDialogUtil;
import com.ysg.utils.YSPUtils;
import com.ysg.utils.YStringUtil;
import com.ysg.utils.YUserUtil;

public class YVipUtil {

    /**
     * 是否为vip:如果不是，先跳转到Vip充值dialog
     */
    public static boolean isVip(Context context, boolean isShowDialog){
        boolean vip = true;
        String config = YSPUtils.getInstance().getString(FileConstant.app_config_file);
        if (YStringUtil.isNotEmpty(config)){
            try {
                AppConfig configBean = JSON.parseObject(config, AppConfig.class);
                String vipSwitch = configBean.getSwitchs().getVipSwitch();
                if (YChannelUtil.getInstance().xiaomi()){
                    vipSwitch = configBean.getXiaomi().getVipSwitch();
                }else if (YChannelUtil.getInstance().huawei()){
                    vipSwitch = configBean.getHuawei().getVipSwitch();
                }else if (YChannelUtil.getInstance().vivo()){
                    vipSwitch = configBean.getVivo().getVipSwitch();
                }else if (YChannelUtil.getInstance().oppo()){
                    vipSwitch = configBean.getOppo().getVipSwitch();
                }
                if (YStringUtil.eq(1, vipSwitch)){
                    vip = YUserUtil.isVip();
                    if (!vip && isShowDialog){
                        YDialogUtil.getInstance().showVipRecharge(context);
                    }
                }
            }catch (Exception e){
            }
        }
        return vip;
    }

    /**
     * 是否为vip:如果不是，先跳转到Vip充值dialog
     */
    public static boolean isChatVip(){
        boolean vip = true;
        String config = YSPUtils.getInstance().getString(FileConstant.app_config_file);
        if (YStringUtil.isNotEmpty(config)){
            try {
                AppConfig configBean = JSON.parseObject(config, AppConfig.class);
                String vipSwitch = configBean.getSwitchs().getChatVipSwitch();
                if (YChannelUtil.getInstance().xiaomi()){
                    vipSwitch = configBean.getXiaomi().getChatVipSwitch();
                }else if (YChannelUtil.getInstance().huawei()){
                    vipSwitch = configBean.getHuawei().getChatVipSwitch();
                }else if (YChannelUtil.getInstance().vivo()){
                    vipSwitch = configBean.getVivo().getChatVipSwitch();
                }else if (YChannelUtil.getInstance().oppo()){
                    vipSwitch = configBean.getOppo().getChatVipSwitch();
                }
                if (YStringUtil.eq(1, vipSwitch) && YDbUtils.getInstance().isThanChatCount() && !YUserUtil.isVip()){
                    return false;
                }
            }catch (Exception e){
            }
        }
        return vip;
    }

    /**
     * 是否为vip:如果不是，先跳转到Vip充值dialog
     */
    public static boolean isChatVipConfig(){
        boolean vip = true;
        String config = YSPUtils.getInstance().getString(FileConstant.app_config_file);
        if (YStringUtil.isNotEmpty(config)){
            try {
                AppConfig configBean = JSON.parseObject(config, AppConfig.class);
                String vipSwitch = configBean.getSwitchs().getChatVipSwitch();
                if (YChannelUtil.getInstance().xiaomi()){
                    vipSwitch = configBean.getXiaomi().getChatVipSwitch();
                }else if (YChannelUtil.getInstance().huawei()){
                    vipSwitch = configBean.getHuawei().getChatVipSwitch();
                }else if (YChannelUtil.getInstance().vivo()){
                    vipSwitch = configBean.getVivo().getChatVipSwitch();
                }else if (YChannelUtil.getInstance().oppo()){
                    vipSwitch = configBean.getOppo().getChatVipSwitch();
                }
                if (YStringUtil.eq(1, vipSwitch)){
                    return false;
                }
            }catch (Exception e){
            }
        }
        return vip;
    }




}
